package com.qidian.mes.md.controller;

import com.qidian.mes.md.service.SupporterService;
import com.qidian.mes.pojo.MaterialSupporter;
import com.qidian.mes.pojo.MdSupport;
import com.qidian.mes.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: CoolPro
 * @Description:
 * @Time: 2024-04-08 22:45
 **/
@RestController
@RequestMapping("/supporters")
@CrossOrigin
public class SupporterController {
    @Autowired
    private SupporterService supporterService;

    @PostMapping
    public QdResult addSupporter(@RequestBody MdSupport supporter) {
        return supporterService.addSupporter(supporter);
    }

    @DeleteMapping("/{id}")
    public QdResult deleteSupporter(@PathVariable Long id) {
        return supporterService.deleteSupporterById(id);
    }

    @PutMapping("/{id}")
    public QdResult updateSupporter(@PathVariable Long id, @RequestBody MdSupport supporter) {
        supporter.setIdSupport(id);
        return supporterService.updateSupporter(supporter);
    }

    @GetMapping("/{id}")
    public QdResult findSupporterById(@PathVariable Long id) {
        return supporterService.findSupporterById(id);
    }

    @GetMapping
    public QdResult findAllSupporters() {
        return supporterService.findAllSupporters();
    }

    @GetMapping("/search")
    public QdResult findSupportersByCriteria(@RequestParam(required = false) String keyword,
                                             @RequestParam(required = false) Integer level,
                                             @RequestParam(required = false) Integer score,
                                             @RequestParam(defaultValue = "0") int page,
                                             @RequestParam(defaultValue = "10") int size) {
        return supporterService.findSupportersByCriteria(keyword, level, score, page, size);
    }

    //获取总条数
    @GetMapping("/count")
    public QdResult getCount() {
        return supporterService.getCount();
    }

    //根据物料ID和供应商类型、供应商名称查询供应商
    @GetMapping("/{page}/{size}/{matId}")
    public QdResult findSupporterByMat(@RequestParam String nameZh, @RequestParam Integer status, @PathVariable Integer page, @PathVariable Integer size, @PathVariable Integer matId) {

        return supporterService.findSupporterByMat(nameZh,status, page, size,matId);
    }

    @PostMapping("/add")
    public QdResult insertMatSup(@RequestBody MaterialSupporter materialSupporter) {
        return supporterService.insertMatSup(materialSupporter);
    }
    @DeleteMapping("/del")
    public QdResult deleteByIdSupport(@RequestParam Integer idSupport,@RequestParam Integer idMat) {
        return supporterService.deleteByIdSupport(idSupport,idMat);
    }

    @PutMapping("/update")
    public QdResult updateSupportCount(@RequestBody String data) {
        return supporterService.updateSupportCount(data);
    }
}
